﻿using System.Diagnostics;
using System.Globalization;
using System.Text;
using Excel.Expressions.Compiler;
using Expressions.Compiler;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests
{


    /// <summary>
    ///This is a test class for Test9_ and is intended
    ///to contain all Test9_ Unit Tests
    ///</summary>
    [TestClass()]
    public class Test9
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        private static Nonterminal<char> CreateGrammar()
        {
            Terminal[] _ = new Terminal[] { '(', ')', 's' };
            Nonterminal<char> grammar = "list-grammar[t]";
            Nonterminal<char> list_expression = "list-expression[t]";
            Nonterminal<char> list_expression_atom = "list-expression-atom[t]";
            Nonterminal<char> list_expression_list = "list-expression-list[t]";
            Nonterminal<char> list_expression_args = "list-expression-args[t]";
            list_expression_list.Definition = new Rules<char>()
            {
                () => '(' + list_expression_args[true] + ')',
            };
            list_expression_args.Definition = new Rules<char>()
            {
                () => list_expression[false] + list_expression_args[true]
            };
            list_expression.Definition = new Rules<char>()
            {
                () => list_expression_atom[false],
                () => list_expression_list[false]
            };
            list_expression_atom.Definition = new Rules<char>()
            {
                () => 's'
            };
            grammar.Definition = new Rules<char> 
            {
                () => list_expression_list[false] + Terminal<char>.Default
            };
            grammar.Initialize();
            grammar.Validate();
            return grammar;
        }

        /// <summary>
        ///A test for Terminal<char> Constructor
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test9_1()
        {
            Nonterminal<char> G = CreateGrammar();
            Parser<char> input = "(s((sss()s)()(s(()ss)((s)s)(s))((s())s(((s))(s())s()))s(()ss(sss))()ss)s(())s()s(((s))s)s)".ToCharArray();

            bool expected = true;
            bool actual = G.Parse(input);

            Assert.AreEqual(expected, actual);
        }
    }
}
